---
category: DOM
created: '2020-04-19'
title: Insert given HTML before an element
updated: '2021-10-13'
---

**JavaScript version**

```js insertHtmlBefore.js
const insertHtmlBefore = (html, ele) => ele.insertAdjacentHTML('beforebegin', html);
```

**TypeScript version**

```ts insertHtmlBefore.ts
const insertHtmlBefore = (html: string, ele: Element): void => ele.insertAdjacentHTML('beforebegin', html);
```
